<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Input输入动画</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background: linear-gradient(45deg,#2980b9, #9b59b6);
        }
        .input-data{
            font-size: 18px;
            position: relative;
            width: 450px;
            height: 40px;
            background: #fff;
            padding: 30px;
            box-shadow: 0 10px 20px rgba(0, 0, 0, .1);
        }
        .input-data input{
            width: 100%;
            height: 100%;
            border: none;
            border-bottom: 2px solid #ccc;
            outline: none;
            font-size: 18px;
        }
        .input-data input:focus ~ label,
        .input-data input:valid ~ label{
            transform: translateY(-20px);
            color: #4158d0;
            font-size: 16px;
        }
        .input-data label{
            position: absolute;
            bottom: 40px;
            left: 30px;
            color: #ccc;
            text-transform: capitalize;
            pointer-events: none;
            transition: all 0.3s ease;
        }
        /* 自定义边框 */
        .input-data .underline{
            position: absolute;
            bottom: 28px;
            height: 2px;
            width: 90%;
            
        }
        .input-data .underline::before{
            content: "";
            position: absolute;
            bottom: 0;
            height:100%;
            width: 100%;
            background-color: #4158d0;
            transform: scale(0);
            transition: all .3s ease;
        }
        .input-data input:focus ~ .underline::before,
        .input-data input:valid ~ .underline::before{
            transform: scale(1);
        }
    </style>
</head>
<body>
    <div class="input-data">
        <!-- required  使其能够使用：focus -->
        <input type="text" required>
        <div class="underline"></div>
        <label for="">name</label>
    </div>
</body>
</html>